<?php

/**
 * File Name：ContentArticlesModel.php
 * File Encoding：UTF-8
 * File New Time：2014-10-14 15:49:26
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class ContentArticlesModel extends BaseModel {

    public function tableName() {
        return '{{content_articles}}';
    }

    public function rules() {
        return array(
            array('title', 'required', 'message' => '标题不能为空！'),
            array('catid', 'required', 'message' => '栏目不能为空！'),
            array('ishtml,keywords,description,content,createtime', 'safe'),
        );
    }

    protected function beforeSave() {
        if ($this->isNewRecord) {
            //改变数据
            $this->createtime = time();
        }
        return true;
    }

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * 根据ID获取文章内容
     * @param type $id
     * @return type
     */
    public function getArticle($id){
        return $this->findByPk($id);
    }
}
